home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5380 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.4 KB

  1. Path: anvil.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c,alt.msdos.programmer
  4. Subject: Re: MSVC based TSRs
  5. Followup-To: alt.msdos.programmer
  6. Date: 12 Feb 1996 10:56:30 -0800
  7. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  8. Message-ID: <4fo2guINNrcv@anvil.ugrad.cs.ubc.ca>
  9. References: <4fm8ll$f6a@news.voicenet.com>
  10. NNTP-Posting-Host: anvil.ugrad.cs.ubc.ca
  11.  
  12. In article <4fm8ll$f6a@news.voicenet.com>, Michael <babump@voicenet.com> wrote:
  13. >I understand the basics of a TSR, and now I'm trying one in MSVC++.  I
  14. >can't use a COM file, becuase __interrupts must be __far.  Which makes
  15. >it harder to do.  How you you make a EXE using multiple segments a
  16. >TSR?  How many paragraphs do you keep(_dos_keep)?  Won't that just
  17. >keep the first segment?  Then all the other segments are unasigned and
  18. >can be over written.  So, how is this accommplished?
  19.  
  20. Funny people are still doing this stuff in 1995! :)
  21.  
  22. The memory model you choose for your program has nothing to do with the
  23. interrupt invocation method used by the hardware, which in this case looks a
  24. lot like a an intersegment call.
  25.  
  26. The C language doesn't provide a way to write interrupt service routines
  27. directly. Operating systems often have assembly language interrupt handlers
  28. which call C routines using C calling conventions. In essence, these routines
  29. provide the necessary "glue".
  30.  
  31. You must write an assembly interrupt handler. The C language has no provisions
  32. for accessing machine registers (unless you use non-portable extensions), and
  33. the interrupt service routine must save these registers plus the flags.
  34.  
  35. The assembly-lanuage service routine can infer what code segment the rest of
  36. your C program occupies, and can hence call your C routines as near functions.
  37. Have you looked at the code for a TSR?  One of the things TSRs typically do is
  38. set the data segment, which is another thing that you need to do if your C code
  39. is to ever correctly reference its variables, and it's another thing that
  40. cannot be done in the C language.
  41.  
  42. Although this is a DOS-specific question, it does raise certain language
  43. issues, such as the distinction between interrupt invocations and function
  44. calls. They are not the same thing, even though in the 8086 they are close
  45. cousins. Thus is is pointless to match the storage type of a procedure to match
  46. the conventions of an interrupt call.
  47.  
  48. Nevertheless, can you guess $here I set the followups to?
  49. -- 
  50.  
  51.